package com.wcy.config;

import com.wcy.filter.GatewayAuthFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

@Configuration
public class FilterConfig {
    @Autowired
    private GatewayAuthFilter gatewayAuthFilter;

    @Bean
    public FilterRegistrationBean<GatewayAuthFilter> customFilterRegistration() {
        FilterRegistrationBean<GatewayAuthFilter> registration =
                new FilterRegistrationBean<>();

        registration.setFilter(gatewayAuthFilter);
        registration.addUrlPatterns("/*");
        registration.setOrder(2); // 设置执行顺序
        registration.setName("customOncePerRequestFilter");
        return registration;
    }
}